<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/media/mediaelement.js"></script>
<link href="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/datatables/DT_bootstrap.css" rel="stylesheet">
<link href="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/responsive-tables/responsive-tables.css" rel="stylesheet">
<link href="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/lightbox/themes/evolution-dark/jquery.lightbox.css" rel="stylesheet">   
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/datatables/jquery.dataTables.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/datatables/DT_bootstrap.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/responsive-tables/responsive-tables.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/lightbox/jquery.lightbox.min.js"></script>
<div id="page-title" class="clearfix">
	<ul class="breadcrumb">
		<li>
			<?php echo CHtml::link('Home',array('/site/index')); ?><span class="divider">/</span>
		</li>
		<li>
			<?php echo CHtml::link('Live Tivi',array('/tv/admin')); ?><span class="divider">/</span>
		</li>
		<li class="active">TV List</li>
	</ul>		
</div> <!-- /.page-title -->
<?php
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('tv-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<div id="horizontal" class="widget widget-form">
	<div class="widget-header">	      				
		<h3>
		     <i class="icon-search"></i>
		     <?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>	      					
		</h3>	
	</div> <!-- /widget-header -->
	<div class="widget-content search-form" style="display:none">
		<?php $this->renderPartial('_search',array(
			'model'=>$model,
		)); ?>
	</div><!-- search-form -->
</div>
<div class="widget widget-table">
	<div class="widget-header">						
		<h3>
			<i class="icon-th-list"></i>
			Manage Live TV						
		</h3>
	</div> <!-- /widget-header -->
		<div class="widget-content">
<?php $form=$this->beginWidget('CActiveForm', array(
    'enableAjaxValidation'=>true,
)); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'tv-grid',
	'dataProvider'=>$model->search(),
	'summaryText'=>'',
	'htmlOptions'=>array('class'=>'table table-striped table-bordered responsive'),
	'pagerCssClass'=>'pagination pagination-centered',
	'columns'=>array(
		array(
            'id'=>'autoId',
            'class'=>'CCheckBoxColumn',
            'selectableRows' => '50',   
        ),
		array(
            'name'=>'name',
            'type'=>'raw',
            'value'=>'"<a data=\"".$data->link."\" href=\"#myModal\" class=\"btn\" data-toggle=\"modal\">".
			CHtml::image(Yii::app()->request->baseUrl."/images/icons/player-icon.png","player-icon.png",array("style"=>"max-width:60px;"))." ".$data->name."</a>"',
			'htmlOptions'=>array("width"=>"30%"),
        ),
        array(
            'name'=>'Description',
            'value'=>'$data->description',
			'htmlOptions'=>array("width"=>"30%"),
        ),
		array(
            'name'=>'Hot',
            'header'=>'Hot',
            'value'=>'($data->hot=="1")?("Yes"):("No")',
        ),
		array(
            'name'=>'order',
            'type'=>'raw',
            'value'=>'CHtml::textField("order[$data->id]",$data->order,array("style"=>"width:50px;"))',
            'htmlOptions'=>array("width"=>"50px"),
        ),
		array(
            'name'=>'active',
            'header'=>'Active',
            'value'=>'($data->active=="1")?("Yes"):("No")'
        ),
		array(
			'header'=>'Action',
			'class'=>'CButtonColumn',
			'buttons'=>array(
		        'delete' => array
		        (
		            'label'=>'Delete',
		        	'imageUrl'=>Yii::app()->request->baseUrl.'/images/icons/delete-file-icon_24.png',
		        	'url'=>'Yii::app()->createUrl("tv/delete", array("id"=>$data->id))',
		        ),
		        'update' => array
		        (
		            'label'=>'Update',
		        	'imageUrl'=>Yii::app()->request->baseUrl.'/images/icons/table-edit-icon_24.png',
		            'url'=>'Yii::app()->createUrl("tv/update", array("id"=>$data->id))',
		        ),
		        'view' => array
		        (
		        	'visible'=>'false'
		        ),
        	),
			'htmlOptions'=>array("width"=>"80px"),
		),
	),
)); ?>
<script>
function reloadGrid(data) {
    $.fn.yiiGridView.update('tv-grid');
}
</script>
<div style="padding-top: 10px;border-top: 1px solid #cccccc;padding-left: 20px;">
<?php echo CHtml::ajaxSubmitButton('Filter',array('tv/ajaxupdate'), array(),array("style"=>"display:none;")); ?>
<?php echo CHtml::ajaxSubmitButton('Activate',array('tv/ajaxupdate','act'=>'doActive'), array('success'=>'reloadGrid'),array('class'=>'btn btn-success','style'=>'margin-right:20px;')); ?>
<?php echo CHtml::ajaxSubmitButton('In Activate',array('tv/ajaxupdate','act'=>'doInactive'), array('success'=>'reloadGrid'),array('class'=>'btn btn-warning','style'=>'margin-right:20px;')); ?>
<?php echo CHtml::ajaxSubmitButton('Active Hot',array('tv/ajaxupdate','act'=>'doHot'), array('success'=>'reloadGrid'),array('class'=>'btn btn-success','style'=>'margin-right:20px;')); ?>
<?php echo CHtml::ajaxSubmitButton('Inactive Hot',array('tv/ajaxupdate','act'=>'doUnhot'), array('success'=>'reloadGrid'),array('class'=>'btn btn-warning','style'=>'margin-right:20px;')); ?>
<?php echo CHtml::ajaxSubmitButton('Delete',array('tv/ajaxupdate','act'=>'doDelete'), array('success'=>'reloadGrid'),array('class'=>'btn btn-danger','style'=>'margin-right:20px;')); ?>
<?php echo CHtml::ajaxSubmitButton('Update sort order',array('tv/ajaxupdate','act'=>'doSortOrder'), array('success'=>'reloadGrid'),array('class'=>'btn btn-inverse','style'=>'margin-right:20px;')); ?>
</div>
	<?php $this->endWidget(); ?>
</div> <!-- /widget-content -->
</div> <!-- /widget -->
<div class="modal fade hide" id="myModal">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h3>Video</h3>
  </div>
  <div class="modal-body">
  	
  </div>
</div>
<?php $user_agent= $_SERVER['HTTP_USER_AGENT'];?>
<?php 
$part=Yii::app()->params['tv_url_wp'];
$type=Yii::app()->params['tv_type_wp'];
if(strpos((string)$user_agent, "Android")!=false){
	$part=Yii::app()->params['tv_url_android'];
	$type=Yii::app()->params['tv_type_android'];
}elseif(strpos((string)$user_agent, "Mac OS")!=false || strpos((string)$user_agent, "Safari")!=false){
	$part=Yii::app()->params['tv_url_ios'];
	$type=Yii::app()->params['tv_type_ios'];
}elseif(strpos((string)$user_agent, "Windows")!=false){
	$part=Yii::app()->params['tv_url_wp'];
	$type=Yii::app()->params['tv_type_wp'];
	if(strpos((string)$user_agent, "compatible") || strpos((string)$user_agent, "U") ){
		$part=Yii::app()->params['tv_url_mb'];
		$type=Yii::app()->params['tv_type_mb'];
	}
}else{
	$part=Yii::app()->params['tv_url_mb'];
	$type=Yii::app()->params['tv_type_mb'];
}
?>
<script type="text/javascript">
var part="<?php echo $part;?>";
var type="<?php echo $type;?>";
$('.close').click(function(){
	$('.modal-body').html('');
});
$('.btn').click(function(){
	$('.modal-body').html('');
	$('.modal-body').html('<video width="530" height="400" id="player1" src="" type="video/mp4" controls="controls"></video>');
	$("#player1").attr("src",part+$(this).attr("data")+type);
	<?php if(strpos((string)$user_agent, "Android")==false):?>
	MediaElement('player1', {success: function(me) {
//		me.play();
		
		me.addEventListener('timeupdate', function() {
			document.getElementById('time').innerHTML = me.currentTime;
		}, false);
		
		document.getElementById('pp')['onclick'] = function() {
			if (me.paused)
				me.play();
			else
				me.pause();
		};

	}});
	<?php else:?>
	function init() {
    	enableVideoClicks();
  	}
  	function enableVideoClicks() {
	    var videos = document.getElementsByTagName("video") || [];
	    for (var i = 0; i < videos.length; i++) {
	      // TODO: use attachEvent in IE
	      videos[i].addEventListener("click", function(videoNode) {
	        return function() {
	          videoNode.play();
	        };
	      }(videos[i]));
	    }
	  }
  	init();
  <?php endif;?>
});
</script>